{include file="Public:header2"/}
<body style="min-height: 100%;background-color: #fff">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form onsubmit="return false;">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">角色名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" value="{$info.title}" lay-verify="required" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">角色描述</label>
                                <div class="layui-input-block">
                                    <textarea name="describe" class="layui-textarea"   placeholder="请输入角色描述">{$info.describe}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">选择权限</label>
                                {foreach $menu as $k => $v}
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <input type="checkbox"  id="p_{$k}" {if $v.pcheck eq 1} checked {/if} data-value="{$k}"  lay-filter="pall" lay-skin="primary" title="{$v.name}">
                                        <br>
                                        <div class="layui-input-block" style="margin-left: -90px;margin-top: -10px; display: inline-block">
                                        </div>
                                        {foreach $v.son as $s => $so}
                                        <div class="layui-input-block" style="width: 5px; display: inline-block">
                                            <input  type="checkbox" class="son_{$k}"  {if $so.check eq 1} checked {/if}   data-value="{$k}" name="quanxian[]" value="{$so.name}" lay-filter="sall"  lay-skin="primary" title="{$so.name}">
                                        </div>
                                        {/foreach}
                                    </div>
                                </div>
                                {/foreach}
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <input type="hidden" name="id" value="{$info.id}">
                                    <button class="layui-btn" onclick="return check()">确认保存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form'], function(){
        var $ = layui.$;
        var form = layui.form
        form.on('checkbox(pall)', function(obj){
            var check = obj.elem.checked;
            var msg = obj.elem.dataset.value;
            var sonClassStr = '.son_'+msg;
            if (check == true){
                $(sonClassStr).prop("checked",true);
            }else{
                $(sonClassStr).prop("checked",false);
            }
            form.render();
        });
        form.on('checkbox(sall)', function(obj){
            var msg = obj.elem.dataset.value;
            var checkNum = $(".son_"+msg+":checked").length;
            $('#p_'+msg).prop("checked",true);
            if (checkNum == 0){
                $('#p_'+msg).prop("checked",false);
            }else{
                $('#p_'+msg).prop("checked",true);
            }
            form.render();
        });
    });


    function check(){
        var url="{:url('/admin/admin_quanxian_edit')}";
        var $ = layui.$;
        var load=layer.load(2);
        $.post(url,$("form").serialize(),function(data){
            if(data.status==1){
                layer.msg(data.msg,{icon:1,time:1500},function(){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    parent.location.reload();
                });
            }else{
                layer.msg(data.msg,{icon:2,anim:6,time:1000},function(){
                    layer.close(load);
                });
            }
        })
    }



</script>